<?php 
// Function for Fonts
function AddFonts ($bodyFont, $h1Font, $h2Font, $h3Font) {
	$fontArray = array('Default','ABeeZee','Archivo+Narrow:400-400italic-700-700italic','Arimo','BenchNine','Cabin:400-400italic-700-700italic','Cabin+Condensed:400-700','Fjalla+One','Open+Sans:400-300-300italic-400italic-700-700italic','Open+Sans+Condensed:300-300italic-700','Roboto:400-100-100italic-300-300italic-400italic-500-500italic-700-700italic-900-900italic','Roboto+Condensed:400-300-300italic-400italic-700-700italic','Six+Caps');
	
	$fontFamilyList = array ('Helvetica Neue','ABeeZee','Archivo Narrow','Arimo','BenchNine','Cabin','Cabin Condensed','Fjalla One','Open Sans','Open Sans Condensed','Roboto','Roboto Condensed','Six Caps');
	if ($bodyFont > 0){
		$fontSetArray[] = $bodyFont;
		$f = $fontFamilyList[$bodyFont] ;
		$bodyFontTxt = "body {font-family:'".$f."', Arial, sans-serif;}";
	}else{
		$bodyFontTxt = "body {font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;}";
	}
	
	if ($h1Font > 0){
		$fontSetArray[] = $h1Font;
		$f = $fontFamilyList[$h1Font] ;
		$h1FontTxt = "h1 {font-family:'".$f."', Arial, sans-serif;}";
	}else{
		$h1FontTxt = "h1 {font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;}";
	}
	if ($h2Font > 0){
		$fontSetArray[] = $h2Font;
		$f = $fontFamilyList[$h2Font] ;
		$h2FontTxt = "h2 {font-family:'".$f."', Arial, sans-serif;}";
	}else{
		$h2FontTxt = "h2 {font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;}";
	}
	if ($h3Font > 0){
		$fontSetArray[] = $h3Font;
		$f = $fontFamilyList[$h3Font] ;
		$h3FontTxt = "h3 {font-family:'".$f."', Arial, sans-serif;}";
	}else{
		$h3FontTxt = "h3 {font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;}";
	}
	//
	$stringa = array(); 
	foreach ($fontSetArray as $value) {
        $c = array_count_values($fontSetArray);
        $n = $c[$value];
        $stringa[array_search($value, $fontSetArray)] = $value;   
	}
	
	foreach ($stringa as $value) {
		$fontTextArray[] = $fontArray[$value];
		}
	
	
	$stringaText = implode(',', $fontTextArray);
	$stringaText = str_replace(",","|",$stringaText); 
	$stringaText = str_replace("-",",",$stringaText); 
	
	$style = "<style>\n ".$bodyFontTxt."\n ".$h1FontTxt."\n ".$h2FontTxt."\n ".$h3FontTxt."\n</style>\n";
	$googLink = "<link href='http://fonts.googleapis.com/css?family=".$stringaText."' rel='stylesheet' type='text/css'>\n";
	
	$AddFont = array($style,$googLink);
	return $AddFont;
	
	///
}


// Function for component row

function ComponentRow($compCol, $compPos, $compSpans, $compFluid, $compColMod01, $compColMod02) 
{
	if ($compFluid == 1) {
	$rowclass = "row-fluid";
	}else{
	$rowclass = "row";
	}
	// One Column
	if ($compCol == 1) {
		$firstSpan = $compSpans[0];
		echo "<div class=\"".$rowclass."\">\n<div class=\"span".$firstSpan."\">\n<div class=\"component-box\">\n<jdoc:include type=\"message\" />\n<jdoc:include type=\"component\" />\n</div>\n</div>\n</div><!-- close bootstrap row -->";
	}
	// Two Columns
	if (($compColMod01 == 1) and ($compCol == 2)) {
		if (($compCol == 2) and ($compPos == 1)) {
			$firstSpan = $compSpans[0];
			$secondSpan = $compSpans[1];
			echo "<div class=\"".$rowclass."\">\n<div class=\"span".$firstSpan."\">\n<div class=\"component-box\">\n<jdoc:include type=\"message\" />\n<jdoc:include type=\"component\" />\n</div>\n</div>\n<div class=\"span".$secondSpan."\"><div class=\"comprow-position-0\"><jdoc:include type=\"modules\" name=\"comprow-position-0\" style=\"XHTML\"  /></div></div></div><!-- close bootstrap row -->";
			
		}
		if (($compCol == 2) and ($compPos == 2)) {
			$firstSpan = $compSpans[0];
			$secondSpan = $compSpans[1];
			echo "<div class=\"".$rowclass."\">\n<div class=\"span".$firstSpan."\">\n<div class=\"comprow-position-0\">\n<jdoc:include type=\"modules\" name=\"comprow-position-0\" style=\"XHTML\"  />\n</div>\n</div>\n<div class=\"span".$secondSpan."\">\n<div class=\"component-box\">\n<jdoc:include type=\"message\" />\n<jdoc:include type=\"component\" />\n</div>\n</div>\n</div><!-- close bootstrap row -->";
		}
	} 
	if (($compColMod01 != 1) and ($compCol == 2)) {
		$firstSpan = 12;
		echo "<div class=\"".$rowclass."\">\n<div class=\"span".$firstSpan."\">\n<div class=\"component-box\">\n<jdoc:include type=\"message\" />\n<jdoc:include type=\"component\" />\n</div>\n</div>\n</div><!-- close bootstrap row -->";
	}	
	// Three Columns
	
	if (($compCol == 3) and ($compPos == 1)) {
		$firstSpan = $compSpans[0];
		$secondSpan = $compSpans[1];
		$thirdSpan = $compSpans[2];
		echo "<div class=\"".$rowclass."\">\n<div class=\"span".$firstSpan."\">\n<div class=\"component-box\">\n<jdoc:include type=\"message\" />\n<jdoc:include type=\"component\" />\n</div>\n</div>\n<div class=\"span".$secondSpan."\">\n<div class=\"comprow-position-0\">\n<jdoc:include type=\"modules\" name=\"comprow-position-0\" style=\"XHTML\"  />\n</div>\n</div>\n<div class=\"span".$thirdSpan."\">\n<div class=\"comprow-position-1\"><jdoc:include type=\"modules\" name=\"comprow-position-1\" style=\"XHTML\"  /></div>\n</div>\n</div><!-- close bootstrap row -->";
	}
	if (($compCol == 3) and ($compPos == 2)) {
		$firstSpan = $compSpans[0];
		$secondSpan = $compSpans[1];
		$thirdSpan = $compSpans[2];
		echo "<div class=\"".$rowclass."\">\n<div class=\"span".$firstSpan."\">\n<div class=\"comprow-position-0\">\n<jdoc:include type=\"modules\" name=\"comprow-position-0\" style=\"XHTML\"  />\n</div>\n</div>\n<div class=\"span".$secondSpan."\">\n<div class=\"component-box\">\n<jdoc:include type=\"message\" />\n<jdoc:include type=\"component\" />\n</div>\n</div>\n<div class=\"span".$thirdSpan."\">\n<div class=\"comprow-position-1\"><jdoc:include type=\"modules\" name=\"comprow-position-1\" style=\"XHTML\"  />\n</div>\n</div></div>\n<!-- close bootstrap row -->";
	}
	if (($compCol == 3) and ($compPos == 3)) {
		$firstSpan = $compSpans[0];
		$secondSpan = $compSpans[1];
		$thirdSpan = $compSpans[2];
		echo "<div class=\"".$rowclass."\">\n<div class=\"span".$firstSpan."\">\n<div class=\"comprow-position-0\">\n<jdoc:include type=\"modules\" name=\"comprow-position-0\" style=\"XHTML\"  />\n</div>\n</div>\n<div class=\"span".$secondSpan."\">\n<div class=\"comprow-position-1\"><jdoc:include type=\"modules\" name=\"comprow-position-1\" style=\"XHTML\"  />\n</div>\n</div>\n<div class=\"span".$thirdSpan."\">\n<div class=\"component-box\">\n<jdoc:include type=\"message\" />\n<jdoc:include type=\"component\" />\n</div>\n</div>\n</div>\n<!-- close bootstrap row -->";
	}

}


// Function for Bootstrap Scaffolding  (spans with same width)
function SpanCol($spanCol,$fluidRow,$addID,$rowId,$respSet)
{ 		
		if ($respSet > 0) {
			if ($respSet == 1) { $respSet = " hidden-phone"; }
			if ($respSet == 2) { $respSet = " hidden-tablet"; }
			if ($respSet == 3) { $respSet = " hidden-desktop"; }
			if ($respSet == 4) { $respSet = " visible-phone"; }
			if ($respSet == 5) { $respSet = " visible-tablet"; }
			if ($respSet == 6) { $respSet = " visible-desktop"; }
		}else{
			$respSet= null;
		}
		if ($fluidRow == 1) { 
			$rowclass = "row-fluid".$respSet; 				
		} else { 
			$rowclass = "row".$respSet; 
		}
		if ($addID != "") {
			$addId = " id='".$addID."'";
		}else{
			$addId = null;
		}
		echo "<!-- Same Width Output -->\n<div class='".$rowclass."'".$addId."><!-- bootstrap row (fluid or not) -->\n";
		$spanNumb = (12/$spanCol);
		for ($s=0; $s<$spanCol; $s=$s+1){
		$position = "row-".$rowId."-position-".$s;
		$childDiv = "brainrow-".$rowId."-child-".$s;
		$divSpan = "<!-- bootsrap span -->\n<div class='span".$spanNumb."'>\n<div class='".$childDiv."'>\n<jdoc:include type=\"modules\" name=\"".$position."\" style=\"XHTML\" /></div></div><!-- /bootsrap span -->\n";
		echo $divSpan;
		}
		echo "</div><!-- /row -->\n";	
}

// Function for Bootstrap Scaffolding  (spans with different width)
function SpanArr($spanArr,$fluidRow,$addID,$rowId,$respSet)
{ 		
		if ($respSet > 0) {
			if ($respSet == 1) { $respSet = " hidden-phone"; }
			if ($respSet == 2) { $respSet = " hidden-tablet"; }
			if ($respSet == 3) { $respSet = " hidden-desktop"; }
			if ($respSet == 4) { $respSet = " visible-phone"; }
			if ($respSet == 5) { $respSet = " visible-tablet"; }
			if ($respSet == 6) { $respSet = " visible-desktop"; }
		}else{
			$respSet= null;
		}
		if ($fluidRow == 1) { 
			$rowclass = "row-fluid".$respSet; 
		}else { 
			$rowclass = "row".$respSet; 
		}
		if ($addID != "") {
			$addId = " id='".$addID."'";
		}else{
			$addId = null;
		}
		echo "<!-- Different Width Output -->\n<div class='".$rowclass."'".$addId."><!-- bootstrap row (fluid or not) -->\n";
		$counter = count($spanArr);
		for($i=0;$i<$counter;$i++){
		$position = "row-".$rowId."-position-".$i;
		$childDiv = "brainrow-".$rowId."-child-".$i;
		echo"<div class='span".$spanArr[$i]."'>\n<div class='".$childDiv."'>\n<jdoc:include type=\"modules\" name=\"".$position."\" style=\"XHTML\" /></div></div>\n";
		}
		echo "</div><!-- /row -->\n";
}

function topRows($rowId,$fluidRow,$addId,$respSet,$addKind,$htmlTop) {
		if ($respSet > 0) {
			if ($respSet == 1) { $respSet = " hidden-phone"; }
			if ($respSet == 2) { $respSet = " hidden-tablet"; }
			if ($respSet == 3) { $respSet = " hidden-desktop"; }
			if ($respSet == 4) { $respSet = " visible-phone"; }
			if ($respSet == 5) { $respSet = " visible-tablet"; }
			if ($respSet == 6) { $respSet = " visible-desktop"; }
		}else{
			$respSet= null;
		}
		if ($fluidRow == 1) { 
			$rowclass = "row-fluid".$respSet; 
		}else { 
			$rowclass = "row".$respSet; 
		}
		if ($addID != "") {
			$addId = " id='".$addID."'";
		}else{
			$addId = null;
		}
		if ($addKind == 0) {
			$divKind = "<jdoc:include type=\"modules\" name=\"row-".$rowId."-position-00\" style=\"XHTML\" />";
		}else{
			$divKind = $htmlTop;
		}
		$divs = "<div class=\"".$rowclass."\">\n<div class=\"span12\">\n".$divKind."\n</div>\n</div>";
		echo $divs;
		
}

?>

